package com.thug.tools;

import org.hibernate.event.PostLoadEvent;
import org.hibernate.event.PostLoadEventListener;
import org.hibernate.event.def.DefaultPostLoadEventListener;

public class ConnectionCloserPostLoadEvenListener extends DefaultPostLoadEventListener implements PostLoadEventListener {

	private static final long serialVersionUID = 1L;

	public void onPostLoad(PostLoadEvent event) {
		super.onPostLoad(event);

		// if a connection, which does not take part into a transaction, is opened, we close it
		if (!event.getSession().getJDBCContext().isTransactionInProgress()) {
			event.getSession().getJDBCContext().getConnectionManager().manualDisconnect();
		}
	}
}
